package org.spring.blog.dao;

import org.spring.blog.pojo.ArticleNoContent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ArticleNoContentDao extends JpaRepository<ArticleNoContent, String>, JpaSpecificationExecutor<ArticleNoContent> {

    ArticleNoContent findOneById(String id);

    @Query(nativeQuery = true, value = "select * from sob_blog_system.tb_article where labels like ?1 and id != ?3 and (state = ?4 or state = ?5) order by create_time desc limit ?2")
    List<ArticleNoContent> listArticleByLikeLabel(String label, int size, String originalArticleId, String publishState, String topState);

    @Query(nativeQuery = true, value = "select * from sob_blog_system.tb_article where id != ?1 and (state = ?3 or state = ?4) order by create_time desc limit ?2")
    List<ArticleNoContent> listLastedArticleBySize(String originalArticleId, int size, String publishState, String topState);
}
